package com.css.resoft.p2pmonitor.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;


public class ReadConifgUtil {
	public static ReadConifgUtil instance;
	public static synchronized ReadConifgUtil getInstance(){
		
		if(instance != null){
			return instance;
		}
		instance = new ReadConifgUtil();
		return instance;
	}
	
	private String host = null;
	private int port = 9090;
	
	private String url = null;
	private String user = null;
	private String password = null;
	
	private ReadConifgUtil(){
		String filePath = null;
		try {
			filePath = new File("").getCanonicalPath()+"//P2PMonitor.ini";
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println(filePath);
		//System.out.println(new File(this.getClass().getResource("").getPath()));
		//String filePath = "C:\\GoDataWeb.ini";
		File file = new File(filePath);
		
		Properties ini = null;
		try {
			ini = new Properties();
			ini.load(new FileInputStream(file));
		} catch (Exception e) {
			e.printStackTrace();
		}

		if(ini.containsKey("host")){
			this.host = ini.get("host").toString();
		}else{
			this.host = "39.107.112.148";
		}
		
		if(ini.containsKey("port")){
			this.port = Integer.parseInt(ini.getProperty("port"));
		}else{
			this.port = 9090;
		}
		
		if(ini.containsKey("url")){
			this.url = ini.get("url").toString();
		}else{
			this.url = "39.107.112.148";
		}
		if(ini.containsKey("user")){
			this.user = ini.get("user").toString();
		}else{
			this.user = "root";
		}
		if(ini.containsKey("password")){
			this.password = ini.get("password").toString();
		}else{
			this.password = "123456";
		}
		
		System.out.println("host: "+this.host);
		System.out.println("port: "+this.port);
		System.out.println("url: "+this.url);
		System.out.println("user: "+this.user);
		System.out.println("password: "+this.password);
		
	}
	
	public String getHost(){
		return host;
	}
	
	public int getPort(){
		return port;
	}
	
	public String getUrl(){
		return url;
	}
	
	public String getUser(){
		return user;
	}
	
	public String getPassword(){
		return password;
	}
	
	
	
}
